package ua.lviv.franko.mlsFunctions.twoDimension;

import java.util.HashMap;
import java.util.Map;

public class ValuesHashStorage {

	private Map<Double, Map<Double, Values>>	valuesStorage;

	public ValuesHashStorage() {
		valuesStorage = new HashMap<Double, Map<Double, Values>>();
	}

	public boolean addValues(Double x, Double y, Values values) {
		if (valuesStorage.containsKey(x)) {
			Map<Double, Values> yVals = valuesStorage.get(x);
			if (yVals.containsKey(y)) {
				return false;
			} else {
				yVals.put(y, values);
				return true;
			}
		} else {
			Map<Double, Values> yVals = new HashMap<Double, Values>();
			yVals.put(y, values);
			valuesStorage.put(x, yVals);
			return true;
		}
	}

	public Values getValues(Double x, Double y) {
		if (valuesStorage.containsKey(x)) {
			Map<Double, Values> yVals = valuesStorage.get(x);
			return yVals.get(y);
		} else {
			return null;
		}
	}

}
